package cn.kmsoft.stgeometry.landm;


import com.vividsolutions.jts.geom.Geometry;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public class StgeoFeature implements Serializable,Comparable {
    private static final long serialVersionUID = 1L;

    private String uuid;
    private String ffid;
    private int order;
    private Geometry geometry;
    private Map<String,Object> properties;
    private String layerFlag;

    public StgeoFeature() {
        this.uuid = UUID.randomUUID().toString();
        this.ffid = UUID.randomUUID().toString();
        this.properties = new HashMap<String,Object>();
    }
    public StgeoFeature(int order) {
        this.uuid = UUID.randomUUID().toString();
        this.ffid = UUID.randomUUID().toString();
        this.order = order;
        this.properties = new HashMap<String,Object>();
    }


    public String getUuid() {
        return uuid;
    }
    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public String getFfid() {
        return ffid;
    }
    public void setFfid(String ffid) {
        this.ffid = ffid;
    }


    public String getLayerFlag() {
        return layerFlag;
    }
    public void setLayerFlag(String layerFlag) {
        this.layerFlag = layerFlag;
    }
    public int getOrder() {
        return order;
    }
    public void setOrder(int order) {
        this.order = order;
    }
    public Geometry getGeometry() {
        return geometry;
    }
    public void setGeometry(Geometry geometry) {
        this.geometry = geometry;
    }


    public Map<String, Object> getProperties() {
        return properties;
    }
    public void setProperties(Map<String, Object> properties) {
        this.properties = properties;
    }
    @Override
    public int compareTo(Object o) {
        StgeoFeature sta2 = (StgeoFeature)o;
        int ord= this.order-sta2.getOrder();
        if( ord ==0 ) {
            return compare(this.uuid, sta2.getUuid());
        }
        return ord;
    }
    public int compare(String o1, String o2) {
        return o2.compareTo(o1);
    }

    @Override
    public int hashCode() {
        int hashCode = this.uuid.hashCode();
        hashCode = 17*hashCode + this.ffid.hashCode();
        return hashCode;
    }

    @Override
    public boolean equals(Object obj) {
        if( !(obj instanceof StgeoFeature)) {
            return false;
        }

        //地址相等
        StgeoFeature stgeoFea = (StgeoFeature) obj;
        //if (this == stgeoFea) {
        //return true;
        //}
        //根据UUID进行判断
        if (stgeoFea.uuid.equals(this.uuid) && stgeoFea.getFfid().equals(this.ffid)) {
            return true;
        } else {
            return false;
        }
    }
}
